<?php
class PromotionAction extends Action{
   public function _initialize(){//初始化
		R("Home.Public","top");
		R("Home.Public","bottom");
   }
   public function index(){//促销产品
	  import("ORG.Com.DiyCache");
	  $mycache = new DiyCache;
	  if(!$mycache->is_cached()){//处理自定义缓存
	     /*安全处理*/
		 checkget();
		 checkpost();
		 
		 $pr_typeid = $_GET["typeid"];
		 if(!empty($pr_typeid)&&!is_numeric($pr_typeid))alert('参数错误');
		 $col_id = getcol_id("product");
		 if(!empty($pr_typeid)){
			$typeid_arr = typeid2child($pr_typeid,"sysclass","col_id = $col_id");
			$typeid_condition = " and typeid in (".implode(",",$typeid_arr).")";
		 }else{
			$typeid_condition = "";
		 }
		 /*安全处理*/
		 
		 //求出促销上部banner  促销中部banner
		 
		 $typeid = 72;
		 $flash = M("flash");
		 $promot_up_banner = $flash->where("typeid = $typeid")->order("sequence desc")->find();
		 $this->assign("promot_up_banner",$promot_up_banner);
		 
		 $typeid = 73;
		 $flash = M("flash");
		 $promot_middle_three = $flash->where("typeid = $typeid")->order("sequence desc")->limit(3)->findAll();
		 $this->assign("promot_middle_three",$promot_middle_three);
		 
		 
		 //求出所有组合套餐
		 $combpr = M("combpr");
		 $comb_list = $combpr->where("comb_pr_ids <> ''")->order("sequence desc")->findAll();
		 $product = M("product");
		 
		 foreach($comb_list as $k=>$v){
			 $comb_pr_ids = $v["comb_pr_ids"];
			 $comb_pr_ids_arr = array_slice(explode(",",$comb_pr_ids),0,3);
			 $sub_str_arr = array();
			 $sub_fee = 0;
			 foreach($comb_pr_ids_arr as $kk=>$vv){
				 $pr_info = $product->where("id = $vv")->find();
				 $comb_list[$k]['pr_list'][]=$pr_info;
				 
				 $sub_str_arr[] = $pr_info['pr_shop_price'];
				 $sub_fee+= $pr_info['pr_shop_price'];
			 }
			 
			 $comb_list[$k]['sub_str'] = implode("+",$sub_str_arr)."=";
			 $comb_list[$k]['sub_fee'] = $sub_fee;
			 $comb_list[$k]['save_fee'] = $sub_fee - $comb_list[$k]['total_price'];
			 
		 }
		 $this->assign("comb_list",$comb_list);
		 
		 //两折特价区  三折特价区   四折特价区
		 $two_list = $product->where("pr_rank = '二折特价区'{$typeid_condition}")->order("sequence desc")->findAll();
		 $this->assign("two_list",$two_list);
		 
		 $three_list = $product->where("pr_rank = '三折特价区'{$typeid_condition}")->order("sequence desc")->findAll();
		 $this->assign("three_list",$three_list);
		 
		 $four_list = $product->where("pr_rank = '四折特价区'{$typeid_condition}")->order("sequence desc")->findAll();
		 $this->assign("four_list",$four_list);
		 
		 if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存 
	     $this->display();
	  }
   }
}